package com.qingke.ssh.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qingke.ssh.bean.Employee;
import com.qingke.ssh.bean.EmployeeLogin;
import com.qingke.ssh.dao.EmployeeDao;

@Service
@Transactional
public class EmployeeService {
	@Autowired
	private EmployeeDao employeeDao;

	public Employee login(String username, String password) {
		EmployeeLogin employeeLogin = employeeDao.login(username, password);
		if (employeeLogin == null) {
			return null;
		}
		return employeeLogin.getEmployee();
	}

	public void add(Employee employee, EmployeeLogin employeeLogin) {
		employeeDao.saveEmployee(employee);
		System.out.println(employee);
		Employee e = employeeDao.getEmployee(employee, employee.getPhone());
		employeeLogin.setEmployee(e);
		employeeDao.saveEmployeeLogin(employeeLogin);
	}

}
